"""
@author: xxw
@file: 读取文件.py
@time: 2023/5/5 14:38
"""
import re
import datetime

time_format = '%Y-%m-%d %H:%M'

visit = {}
with open("scwebsite2_ssl.log") as f:
    for line in f:
        match_obj = re.search(r'\[(.*)\]', line)
        if match_obj:
            # 将时间字符串转化为 datetime 对象
            time_str = match_obj.group(1)
            time_obj = datetime.strptime(time_str, '%d/%b/%Y:%H:%M:%S %z')
            # 取整到分钟
            time = datetime.strftime(time_obj, time_format)
            # 统计每分钟的访问量
            visit[time] = visit.get(time, 0) + 1

        # 输出结果
        for time, count in visit.items():
            print(f'{time}: {count}')